<?PHP
  class ImageServer{
    function insert($path,$name,$description){
      $path        = $GLOBALS['db']->EscapeString($path);
      $name        = $GLOBALS['db']->EscapeString($name);
      $description = $GLOBALS['db']->EscapeString($description);
      $res         = $GLOBALS['db']->Execute("INSERT INTO {'dbprefix'}images (path,name,description) 
                                              VALUES ('".$path."','".$name."','".$description."')");
      if($res){
        $args['path']        = $path;
        $args['name']        = $name;
        $args['description'] = $description;
        EventManager::raiseEvent("image_registered","../",$args);
      }
      return $res;
    }
    
    function getImages(){
      return $GLOBALS['db']->ReadRows("SELECT * FROM {'dbprefix'}images");
    }

    public static function getImageData($path){
      $path = $GLOBALS['db']->EscapeString($path);
      return $GLOBALS['db']->ReadRow("SELECT * FROM {'dbprefix'}images WHERE path = '".$path."'");
    }

    public static function delete($path){
      $path = $GLOBALS['db']->EscapeString($path);
      return $GLOBALS['db']->Execute("DELETE FROM {'dbprefix'}images WHERE path = '".$path."'");
    }

    public static function contains($path){
      return self::getImageData($path) != false;;
    }

    public static function move($oldPath,$newPath){
      $oldPath = $GLOBALS['db']->EscapeString($oldPath);
      $newPath = $GLOBALS['db']->EscapeString($newPath);
      return $GLOBALS['db']->Execute("UPDATE {'dbprefix'}images SET path = '".$newPath."' WHERE path = '".$oldPath."'");
    }
  }
?>
